#0. 导包
import threading
import time
import requests


class XM():
    host = "http://"+"apiv2.higaoyao.com:9527"
    def stay_time(self,headers):
        # 1. 设置资源路径 - 定位接口资源
        url = self.host + "/api/v1/home/syncTime"
        headers = headers
        data = {}
        # 2. 设置提交数据,发送请求
        # 查询所有 无请求数据
        response = requests.post(url, headers=headers, json=data, verify=False)
        response.encoding = "utf-8"
        # 3 查看响应结果
        # 3.1 查看状态码
        code = response.status_code
        print(code)
        # 3.2 查看返回结果文本格式  字符串
        text = response.json()
        print(text)



    def get_money( self,headers ):
        # 1. 设置资源路径 - 定位接口资源
        url = self.host +"/api/v1/award/rightGold"
        headers = headers
        data = {}
        # 2. 设置提交数据,发送请求
        # 查询所有 无请求数据
        response = requests.post(url, headers=headers, data=data,verify=False)
        response.encoding = "utf-8"
        # 3 查看响应结果
        # 3.1 查看状态码
        code = response.status_code
        print(code)
        # 3.2 查看返回结果文本格式  字符串
        text = response.json()
        print(text)

    def look_video(self,headers):
        # 1. 设置资源路径 - 定位接口资源
        url = self.host + "/api/v1/award/video/look"
        headers = headers
        data = {"awardType":2}
        # 2. 设置提交数据,发送请求
        # 查询所有 无请求数据
        response = requests.post(url, headers=headers, json=data, verify=False)
        response.encoding = "utf-8"
        # 3 查看响应结果
        # 3.1 查看状态码
        code = response.status_code
        print(code)
        # 3.2 查看返回结果文本格式  字符串
        text = response.json()
        print(text)
        return text['msg']

    def turntable(self,headers):
        # 1. 设置资源路径 - 定位接口资源
        url = self.host + "/api/v1/award/turntable/turn"
        headers = headers
        data = {}
        # 2. 设置提交数据,发送请求
        # 查询所有 无请求数据
        response = requests.post(url, headers=headers, data=data, verify=False)
        response.encoding = "utf-8"
        # 3 查看响应结果
        # 3.1 查看状态码
        code = response.status_code
        # print(code)
        # 3.2 查看返回结果文本格式  字符串
        text = response.json()
        print(text)
        return text['msg']


    def start_demo(self,heads):
        self.stay_time(heads)
        for i in range(10):
            self.get_money(heads)
        for i in range(60):
            a = self.look_video(heads)
            if a == '当天观看视频次数已达上限':
                break
            time.sleep(5)
        for n in range(120):
            b = self.turntable(heads)
            if b == '转盘券不足':
                break
            time.sleep(5)
    def stay(self, heads):
        self.start_demo(heads)
        for i in range(300):
            time.sleep(10)
            a.stay_time(heads)

if __name__ == '__main__':
    a = XM()
    heads = [ # 大号
        {"Authorization": "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJkZXYiLCJpYXQiOjE1ODg2NzkyMjQsImV4cCI6MTU5MTI3MTIyNCwibmJmIjoxNTg4Njc5MjI0LCJ1aWQiOjMyNTgxODE3fQ.MF1sWaKr2K44g4cbuTgfNnssBhroARgcH70NpcNx6mE",  # 大号
              "Content-Type": "application/json;charset=UTF-8"},
        {"Authorization": "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJkZXYiLCJpYXQiOjE1ODY1MDgyNTAsImV4cCI6MTU4OTEwMDI1MCwibmJmIjoxNTg2NTA4MjUwLCJ1aWQiOjMyNTg4MjIyfQ.SLnz3eOV8TK7wY24l3DSIVFT0KVw1ijFbK_BcjEGIjs",
        "Content-Type": "application/json;charset=UTF-8"},
             {"Authorization":"Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJkZXYiLCJpYXQiOjE1ODY1MTUxMzgsImV4cCI6MTU4OTEwNzEzOCwibmJmIjoxNTg2NTE1MTM4LCJ1aWQiOjMzNTcwNDIxfQ.9OPPTp5IQN-Q1qtGKY614mjzp_CCjkKGXhlCQIy-Mco",
               "Content-Type": "application/json;charset=UTF-8"},
             {"Authorization":"Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJkZXYiLCJpYXQiOjE1ODY1MTU5NTcsImV4cCI6MTU4OTEwNzk1NywibmJmIjoxNTg2NTE1OTU3LCJ1aWQiOjMzNTkzMDE1fQ.glBLdPJpK5fLI5J_Bl_fCc7JZoi3HG1B3JjqR0Rj1dc",
               "Content-Type": "application/json;charset=UTF-8"},
             # 乐视破屏
             {"Authorization": "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJkZXYiLCJpYXQiOjE1ODg2ODIwMDksImV4cCI6MTU5MTI3NDAwOSwibmJmIjoxNTg4NjgyMDA5LCJ1aWQiOjM0NTU5MTk3fQ._vj05JpJsMW3QTgYCeBRbujFdgFNwM-tZshRQOHaeWM",
              "Content-Type": "application/json;charset=UTF-8"}
             ]
    threads = []
    for i in heads:
        t = threading.Thread(target=a.stay, args=(i,))
        threads.append(t)
    for i in range(len(heads)):
        threads[i].start()
    for i in range(len(heads)):
        threads[i].join()

